package com.zhiyou100.pra;

/**
 * 模拟售票
 */
public class Ticket {
    //定义静态变量表示票的初始值
    static int initialTicket = 100;

    /**
     * 定义方法表示要售票
     * 每次只能卖一张票
     */
    public void ticketSales(int ticketSales) {
        if (ticketSales == 1 && initialTicket > 0) {
            initialTicket = initialTicket - ticketSales;//表示余票
            System.out.println("您购买成功，我们还剩余" + initialTicket + "张票");
        } else {
            System.out.println("您输入的票数有问题，请您每次只购买一张");
        }
    }

    public static void main(String[] args) {
        //窗口1
        Ticket ticket1 = new Ticket();
        ticket1.ticketSales(1);
        ticket1.ticketSales(1);
        //窗口2
        Ticket ticket2 = new Ticket();
        ticket2.ticketSales(1);
        ticket2.ticketSales(1);

    }
}